package com.kede.app.domain;

import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.List;

/**
* @description /
* @author Pr.li
* @date 2023-07-02
**/
@Entity
@Data
@Table(name="t_zhi_category")
@EntityListeners(AuditingEntityListener.class)
public class ZhiCategory implements Serializable {
    /**
    * 
    */
    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    private Integer id;
    /**
    * 
    */
    @ApiModelProperty(value = "pid")
    @Column(name = "`pid`")
    private Integer pid;
    /**
    * 品类名称
    */
    @ApiModelProperty(value = "品类名称")
    @Column(name = "`name`",nullable = false)
    @NotBlank
    private String name;
    /**
    * 默认用户价格
    */
    @ApiModelProperty(value = "默认用户价格")
    @Column(name = "`default_user_money`",nullable = false)
    private BigDecimal defaultUserMoney;

    /**
     * 默认用户德币
     */
    @ApiModelProperty(value = "默认用户德币")
    @Column(name = "`default_user_debi`",nullable = false)
    private BigDecimal defaultUserDebi;
    /**
    * 默认门店价格
    */
    @ApiModelProperty(value = "默认门店价格")
    @Column(name = "`default_store_money`",nullable = false)
    private BigDecimal defaultStoreMoney;
    /**
    * 默认区代价格
    */
    @ApiModelProperty(value = "默认区代价格")
    @Column(name = "`default_qu_money`",nullable = false)
    private BigDecimal defaultQuMoney;
    /**
    * 默认市代价格
    */
    @ApiModelProperty(value = "默认市代价格")
    @Column(name = "`default_shi_money`",nullable = false)
    private BigDecimal defaultShiMoney;
    /**
    * 
    */
    @ApiModelProperty(value = "createTime")
    @Column(name = "`create_time`")
    @CreatedDate
    private Timestamp createTime;
    /**
    * 
    */
    @ApiModelProperty(value = "updateTime")
    @Column(name = "`update_time`")
    @LastModifiedDate
    private Timestamp updateTime;
    /**
    * 
    */
    @ApiModelProperty(value = "createBy")
    @Column(name = "`create_by`")
    @CreatedBy
    private String createBy;
    /**
    * 
    */
    @ApiModelProperty(value = "updateBy")
    @Column(name = "`update_by`")
    @LastModifiedBy
    private String updateBy;
    /**
    * 所属组
    */
    @ApiModelProperty(value = "所属组")
    @Column(name = "`group`")
    private String group;


    @ApiModelProperty(value = "是否启用")
    @Column(name = "`is_active`")
    private Integer isActive;

    @ApiModelProperty(value = "类型")
    @Column(name = "`is_weight`")
    private Integer isWeight;

    @ApiModelProperty(value = "是否热门")
    @Column(name = "`is_hot`")
    private Integer isHot;

    @ApiModelProperty(value = "热门图标")
    @Column(name = "`hot_url`")
    private String hotUrl;

    @ApiModelProperty(value = "需要上传的图片，（中文的）多个用，分来")
    @Transient
    private ZhiImgs imgs;

    @ApiModelProperty(value = "该分类绑定的动作")
    @Transient
    private List<ZhiAction> zhiActionList;

    public void copy(ZhiCategory source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    public BigDecimal getDefaultUserMoney() {
        if(defaultUserMoney ==null){
            defaultUserMoney = new BigDecimal("0");
        }
        return defaultUserMoney;
    }
}
